package com.huike.stock_analysis.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.service.GrowService;

/**
 * 
 * @author mzLEI
 *  成长能力接口
 */
@RestController
@CrossOrigin(value = "*")
@RequestMapping("/grow")
public class GrowController {
	@Autowired
	private GrowService gService;
	
	//总资产增长率
	@RequestMapping("/assetsGrowRatio")
	public String assetsGrowRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = gService.assetsGrowRatio(stock);
		
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	
	//营业收入增长率
	@RequestMapping("/businessIncomeGrowRatio")
	public String businessIncomeGrowRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = gService.businessIncomeGrowRatio(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//固定资产比重
	@RequestMapping("/fixesAssetsRatio")
	public String fixesAssetsRatio(String stock) {
		if(stock == null) return "null";
		return gService.fixesAssetsRatio(stock);
	}
	
	//净利润增长率
	@RequestMapping("/netProfitGrowRatio")
	public String pnetProfitGrowRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = gService.netProfitGrowRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	/*
	//净资产增长率
	@RequestMapping("/netAssetsGrowRatio")
	public String reinvestmentRatio() {
		Map<String, String> map = gService.netAssetsGrowRatio();
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	*/
	
	
}
